<template>
  <NewMianModule :title="startT + title" num="08">
    <div class="conent">
      <div class="content_item_wrap mb" v-for="(item, index) in detailListTop" :key="index">
        <div class="content_title top-title_40">{{ item.name }}</div>
        <div class="num_wrap">
          <div class="content_num">{{ parseFloat(item.value).toFixed(2) }}</div>
          <div class="content_unit">{{ item.util }}</div>
        </div>
      </div>

      <div class="bottom_wrap">
        <div class="content_item_wrap" v-for="(item, index) in detailListBottom" :key="index">
          <div class="content_title">{{ item.name }}</div>
          <div class="num_wrap">
            <div class="content_num bot-title_68" style="font-size: 60px">{{ parseFloat(item.value).toFixed(2) }}</div>
            <div class="content_unit" style="font-size: 32px">{{ item.util }}</div>
          </div>
        </div>
      </div>
    </div>
  </NewMianModule>
</template>

<script>
import NewMianModule from '../../../NewMianModule/index'
import http from '@/utils/request'

//import { rightData } from '../../../right/newOneRight/rightData.js'
export default {
  props: {
    title: {
      type: String,
      default: '',
    },
    startT: {
      type: String,
      default: '',
    },
    selectedName: {
      type: String,
      default: '',
    },
    qgData: {
      type: Object,
      default: () => {}, // es6的箭头函数
    },
  },
  components: {
    NewMianModule,
  },
  data() {
    return {
      detailListTop: [this.qgData['08'][0]],
      detailListBottom: [this.qgData['08'][1], this.qgData['08'][2]],
    }
  },
  mounted() {
    //昨日新增
    this.saveLeftData()
    this.queryLeftData()
  },
  methods: {
    async queryLeftData() {
      let _ = this
      try {
        let str = _.selectedName ? _.selectedName : 'quanGuo'
        const res = await http.get('/data/user/getAmountIncrementYesterday?taxAmountKey=1&recyclingAmountKey=' + str, {
          isLoading: false,
          baseURL: process.env.VUE_APP_API_ST_URL,
        })
        _.qgData['08'][2].value = res['recyclingAmountIncrement']
      } catch (e) {
        console.log(e)
      }
    },
    formatDate(date) {
      let d = new Date(date),
        month = '' + (d.getMonth() + 1),
        day = '' + d.getDate(),
        year = d.getFullYear()

      if (month.length < 2) month = '0' + month
      if (day.length < 2) day = '0' + day

      return [year, month, day].join('-')
    },
    async saveLeftData() {
      //taxAmountKey和taxAmount不要了 recyclingAmount 日均余额昨日新增
      let _ = this
      try {
        let str = _.selectedName ? _.selectedName : 'quanGuo'
        let a = _.formatDate(new Date())
        await http.get(
          '/data/user/saveAmount?date=' +
            a +
            '&taxAmount=' +
            this.qgData['09'][0].value +
            '&recyclingAmount=' +
            this.qgData['08'][0].value +
            '&taxAmountKey=1&recyclingAmountKey=' +
            str,
          { isLoading: false, baseURL: process.env.VUE_APP_API_ST_URL }
        )

        /*let str = _.selectedName?_.selectedName:'quanguo';
        await http.get(
            '/data/user/saveAmount?date=2023-02-07&taxAmount=1&recyclingAmount=111115&taxAmountKey=1&recyclingAmountKey='+str,
            { isLoading: false, baseURL: process.env.VUE_APP_API_ST_URL }
        )*/
      } catch (e) {
        console.log(e)
      }
    },
  },
}
</script>

<style lang="scss" scoped>
@import '../rightBase.css';
.conent {
  width: 100%;
  height: calc(100% - 20px);
  padding-top: 20px;
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
}

.bottom_wrap {
  width: calc(100% - 20px);
  padding-right: 20px;
  display: flex;
  justify-content: space-between;
}
</style>
